<?php
/*  if ($fh) {
while (!feof($fh)) {//逐条读数据
$line_data = fgets($fh);

//echo "JUXIN<br/>";
$time = substr($line_data, 0, 19);//得到时间
$data = substr($line_data, 24);//去除部分，得到json
$obj = json_decode($data,True);
//print_r($obj);exit;
/*数据库中的数据：
msg的类型，判断消息类型，是否是图片
user_name@@和from_name判断是否是群消息（除群主外的）
user_id群名字，用来显示
content来判断是否是加群的，还有粉丝数
$mtype =$obj['msg']['MsgType'];//msg的type类型
$user_id = $obj['user']['id'];//用户的id
$user_name = $obj['user']['name'];
$from = $obj['msg']['FromUserName'];
$content = $obj['msg']['Content'];
$content = $conn->real_escape_string($content);//去除转义字符的情况
//  echo $content."<br/>";
//echo $time." ".$mtype." ".$user_id." ".$user_name." ".$from." ".$content." ";
$from = substr($from, 0, 2);//判断是否是群消息
if ($from === "@@") {

//群消息，提交到数据库中
if ($mtype == 1 || $mtype == 3)//是群消息，且不是初始化51，而是群内人发文本1，发图片3
// var_dump($line_data);
//插入
// echo $time."!!!!!!!!!<br/>";
$sql= "INSERT INTO msg (hdid,date,mtype,content,user_id,user_name) VALUES ('$hdid','$time','$mtype','$content','$user_id','$user_name')";
if($sql!=NUll) {
if ($conn->query($sql) === TRUE) {
echo "新记录插入成功a<br/>";
//      echo $time."<br/>";
//   echo $sql."<br/>";
} else {
echo "Error: " . $conn->error . "Juxin" . $sql . "<br>";
}
}else{
echo "SQL为空a<br/>";
}
} else if (strpos($content, $come) && $mtype == 10000) {//是群消息，且是系统消息come是加入群内的
$sql= "INSERT INTO msg (hdid,date,mtype,content,user_id,user_name) VALUES ('$hdid','$time','$mtype','$content','$user_id','$user_name')";
// echo "JUXIN";
if($sql!=NUll) {
if ($conn->query($sql) === TRUE) {
echo "新记录插入成功b<br/>";
//    echo $time."<br/>";
//    echo $sql."<br/>";
} else {
echo "Error: " . $conn->error . "Juxin" . $sql . "<br>";
}
}else{
echo "SQL为空b<br/>";
}

} else if ($from !== "@@" && $mtype == 10000) {//不是群粉丝，系统消息，加个人好友的，go是添加到通讯录的
if (strpos($content, $go)) {
$sql= "INSERT INTO p_msg (hdid,date,mtype,content) VALUES ('$hdid','$time','$mtype','$content')";
if($sql!=NUll) {
if ($conn->query($sql) === TRUE) {
echo "新记录插入成功c<br/>";
//    echo $time."<br/>";
//      echo $sql."<br/>";
} else {
echo "Error: " . $conn->error . "Juxin" . $sql . "<br>";
}
}else{
echo "SQL为空c<br/>";
}
}
}
}
}*/
?>